package org.devio.secondlevelmenu.spinner;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.devio.secondlevelmenu.R;

import java.util.List;

public class NormalSpinnerAdapter extends BaseAdapter {

    private Context mcontext;
    private List<String> list_string;
    private NormalSpinnerAdapter.ViewHolder viewHolder;
    private int selectPosition = 0;


    public interface AdapterItemClick {
        public void itemClick(int position,String string_content);
    }

    public NormalSpinnerAdapter(Context context, List list_string) {
        mcontext = context;
        this.list_string = list_string;
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }


    @Override


    public int getCount() {
        return list_string.size();
    }

    @Override
    public Object getItem(int position) {
        return list_string.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.item_labeldetail_spinner, null);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.txt);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(list_string.get(position));
        if (selectPosition == position) {
            viewHolder.textView.setTextColor(mcontext.getResources().getColor(R.color.colorPrimary));
        } else {
            viewHolder.textView.setTextColor(mcontext.getResources().getColor(R.color.color_ff3c3c3c));

        }
        return convertView;
    }


    class ViewHolder {

        private TextView textView;
    }
}
